package com.kzj.controller;


import com.kzj.common.re.Result;
import com.kzj.domain.User;
import com.kzj.domain.dto.UserLoginDTO;
import com.kzj.domain.dto.UserRegisterDTO;
import com.kzj.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kzj
 * @since 2023-11-15
 */
@CrossOrigin(origins = "/**")
@RestController
@RequestMapping("/user")
@Api(tags = "用户接口")
public class UserController {
    @Autowired
    UserService userService;
//    @PostMapping("/register")
//    @ApiOperation("")
//    public Result register(@RequestBody UserRegisterDTO userRegisterDTO, HttpServletRequest request)
//    {
//        return userService.register(userRegisterDTO,request);
//    }
//    @GetMapping("/getImageCode")
//    @ApiOperation("")
//    public Result getImageCode(){
//
//    }
    @GetMapping("/sendMessageCode")
    public Result sendMessageCode(String phone,HttpServletRequest request)
    {
        return userService.sendMessageCode(phone,request);
    }

    @PostMapping("/login")
    @ApiOperation("")
    public Result login(@RequestBody UserLoginDTO userLoginDTO,HttpServletRequest request)
    {
        return userService.login(userLoginDTO,request);
    }
    @GetMapping("/{phone}")
    public Result getByPhone(@PathVariable String phone)
    {
        return userService.getByPhone(phone);
    }
    @PutMapping("/alterInformation")
    public Result alterInformation(@RequestBody User user)
    {
        return  userService.updateByPhone(user);
    }





}

